<template>
    <div class="oldversion">
        <Header :title="header_title" :right_text1="right_text"></Header>
        <div class="topheader page">
            <div class="tip"></div>
            <van-cell-group inset class="textarea infofield oldtextarea">
                <van-field v-model="name" :type="type" rows="1" autosize type="textarea" :maxlength="header_title=='姓名'?'12':(header_title=='详细地址')?'50':'100' " placeholder="请输入" :show-word-limit="(header_title=='姓名' || header_title=='详细地址')?true:false" />
            </van-cell-group>
        </div>
    </div>
</template>

<script>
import Header from '@/components/oldheader.vue'
import { Toast } from 'vant';
export default {
    components: {
        Header
    },
    data() {
        return {
            header_title: '',
            right_text: '保存',
            name: '',
            type: 'text'
        }
    },
    mounted() {
        let params = this.$route.params;
        this.header_title = params.page;
        var data = this.$store.state.myInfo;
        if(params.page == '姓名') {
            this.name = data.realName;
        } else if(params.page == '证件号码') {
            this.name = data.identityNumber;
        } else if(params.page == '工作年限') {
            this.name = data.workingYear;
            this.type = 'number';
        } else if(params.page == '联系电话') {
            this.name = data.phoneNumber;
        } else if(params.page == '详细地址') {
            this.name = data.areaDetail;
        }
    },
    methods: {
        rightMethod() {
            var data = this.$store.state.myInfo;
            if (this.header_title == '证件号码') {
                var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                if (reg.test(this.name) === false) {
                    Toast({ message: '请输入正确的证件号码' });
                    return;
                }else{
                    data.identityNumber = this.name;
                }
            } else if (this.header_title == '联系电话') {
                if (this.name.length != 11) {
                    Toast({ message: '请输入正确的联系电话' });
                    return;
                } else {
                    data.phoneNumber = this.name;
                }
            } else if(this.header_title == '姓名') {
                if(this.name.length<2){
                    Toast("最少2个字")
                    return;
                }
                data.realName = this.name;
            } else if(this.header_title == '工作年限') {
                data.workingYear = this.name;

            } else if(this.header_title == '详细地址') {
                data.areaDetail = this.name;
            }
            this.$store.commit('setmyInfo', data);
            this.$router.replace('/oldbase');
        },
        goback() {
            this.$router.replace('/oldbase');
        }
    }
}
</script>

<style scoped>
.tip {
    height: 0.32rem;
}

.textarea .van-cell {
    padding: unset;
}

.van-cell-group--inset.textarea {
    margin: unset;
}
</style>